package org.linuxsogood.boot.jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

/**
 * @author honway.liu
 * @date 2019/8/30 9:41 PM
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class JedisDemo {

    private static final String HOST = "192.168.199.212";
    private static final int PORT = 6379;

    public static void main(String[] args) {
        Jedis jedis = new Jedis(HOST, PORT);

        /**
         * 5862 不使用pipeline
         */
        /*long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            jedis.hset("hashset" + i, "name", "value:" + i);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        */

        /**
         * 使用pipelined 320
         */
        long s = System.currentTimeMillis();
        Pipeline pipelined = jedis.pipelined();
        for (int i = 0; i < 10000; i++) {
            pipelined.hset("hash" + i, "name", "value" + i);
        }
        pipelined.syncAndReturnAll();
        System.out.println(System.currentTimeMillis() - s);
    }
}
